<template>
  <div class="container">
    <div class="apply-container">
      <div class="apply-container-head"></div>
      <div class="apply-container-body">
        <div class="apply-container-body-title">
          <div class="apply-container-body-title-font">修改车辆档案</div>
          <div class="apply-container-body-title-return">
            <el-button size="small" @click="goBackPage">返回</el-button>
          </div>
        </div>
        <el-divider class="apply-container-body-title-line"></el-divider>
        <div class="apply-container-body-content">
          <el-form :model="AutoArchives" label-width="100px" ref="AutoArchives" label-position="LabelPosition"
            :rules="AutoArchivesRules" style="width: 100%;">
            <el-form-item label="车辆编号:" prop="InputAutoId" style="width: 40%;">
              <el-input disabled v-model="AutoArchives.InputAutoId"></el-input>
            </el-form-item>
            <el-form-item label="车牌号:" prop="InputAutoPlateNum" style="width: 40%;">
              <el-input v-model="AutoArchives.InputAutoPlateNum" clearable></el-input>
            </el-form-item>
            <el-form-item label="车架号:" prop="InputAutoFrameNum" style="width: 40%;">
              <el-input disabled v-model="AutoArchives.InputAutoFrameNum"></el-input>
            </el-form-item>
            <el-form-item label="车型:" prop="SelectAutoType" style="width: 40%;">
              <el-input disabled v-model="AutoArchives.SelectAutoType"></el-input>
            </el-form-item>
            <el-form-item label="座位数:" prop="InputSeatNum" style="width: 40%;">
              <el-input disabled v-model="AutoArchives.InputSeatNum"></el-input>
            </el-form-item>
            <el-form-item label="所需驾照:" prop="SelectLicenseType" style="width: 40%;">
              <el-input disabled v-model="AutoArchives.SelectLicenseType"></el-input>
            </el-form-item>
            <el-form-item label="用车年限:" prop="InputAutoAge" style="width: 40%;">
              <el-input v-model="AutoArchives.InputAutoAge" clearable></el-input>
            </el-form-item>
            <el-form-item label="车辆颜色:" prop="InputAutoColor" style="width: 40%;">
              <el-input v-model="AutoArchives.InputAutoColor" clearable></el-input>
            </el-form-item>
            <el-form-item label="加油卡卡号:" prop="InputGasCardNumber" style="width: 45%;">
              <el-input v-model="AutoArchives.InputGasCardNumber" clearable></el-input>
            </el-form-item>
            <div class="apply-container-body-content-submit">
              <el-button type="primary" @click="AutoArchiveUpdate('AutoArchives')">提交</el-button>
            </div>
          </el-form>
        </div>
      </div>
      <div class="apply-container-footer"></div>
    </div>
  </div>
</template>
  
<script>
import { autoArchiveUpdate } from '../../api/archives.js'
export default {
  name: 'UpgradeAutoArchives',
  data() {
    return {
      LabelPosition: 'right',
      AutoArchives: {
        InputAutoId: null,
        InputAutoPlateNum: null,
        InputAutoFrameNum: null,
        SelectAutoType: null,
        InputSeatNum: null,
        SelectLicenseType: null,
        InputAutoAge: null,
        InputAutoColor: null,
        InputGasCardNumber: null,
      },
      AutoArchivesRules: {
        InputAutoPlateNum: [{ required: true, message: '请输入车牌号', trigger: 'blur' },],
        InputAutoFrameNum: [{ required: true, message: '请输入车架号', trigger: 'blur' },],
        SelectAutoType: [{ required: true, message: '请选择车型', trigger: 'change' },],
        InputSeatNum: [{ required: true, message: '请输入座位数', trigger: 'blur' },],
        SelectLicenseType: [{ required: true, message: '请输入所需驾照类型', trigger: 'blur' },],
        InputAutoAge: [{ required: true, message: '请输入用车年限', trigger: 'blur' },],
        InputAutoColor: [{ required: true, message: '请输入车辆颜色', trigger: 'blur' },],
        InputGasCardNumber: [{ required: true, message: '请输入加油卡卡号', trigger: 'blur' },],
      },
      SubmitAutoArchive: {
        autoId: null,
        autoPlateNum: null,
        autoFrameNum: null,
        autoType: null,
        seatNum: null,
        licenseType: null,
        gasCardNumber: null,
        autoAge: null,
        autoColor: null
      },
    }
  },

  methods: {
    initFormDetail() {
      this.AutoArchives.InputAutoPlateNum = this.$route.query.InputAutoPlateNum;
      this.AutoArchives.InputAutoId = this.$route.query.InputAutoId;
      this.AutoArchives.InputAutoFrameNum = this.$route.query.InputAutoFrameNum;
      this.AutoArchives.SelectAutoType = this.$route.query.SelectAutoType;
      this.AutoArchives.InputSeatNum = this.$route.query.InputSeatNum;
      this.AutoArchives.SelectLicenseType = this.$route.query.SelectLicenseType;
      this.AutoArchives.InputAutoAge = this.$route.query.InputAutoAge;
      this.AutoArchives.InputAutoColor = this.$route.query.InputAutoColor;
      this.AutoArchives.InputGasCardNumber = this.$route.query.InputGasCardNumber;
    },

    AutoArchiveUpdate(formName) {

      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$confirm('此操作将修改此车辆档案, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {

            this.SubmitAutoArchive.autoId = this.AutoArchives.InputAutoId;
            this.SubmitAutoArchive.autoAge = this.AutoArchives.InputAutoAge;
            this.SubmitAutoArchive.autoColor = this.AutoArchives.InputAutoColor;
            this.SubmitAutoArchive.autoFrameNum = this.AutoArchives.InputAutoFrameNum;
            this.SubmitAutoArchive.autoPlateNum = this.AutoArchives.InputAutoPlateNum;
            this.SubmitAutoArchive.autoType = this.AutoArchives.SelectAutoType;
            this.SubmitAutoArchive.gasCardNumber = this.AutoArchives.InputGasCardNumber;
            this.SubmitAutoArchive.licenseType = this.AutoArchives.SelectLicenseType;
            this.SubmitAutoArchive.seatNum = this.AutoArchives.InputSeatNum;

            autoArchiveUpdate(this.SubmitAutoArchive).then(res => {
              if (res.data.code === '0') {
                this.$message({
                  message: "修改成功",
                  duration: 2000,
                  showClose: true,
                  type: 'success'
                });
                this.goBackPage()
              }
              else {
                this.$message.error(res.data.msg);
              }
            }).catch((err) => {
              console.log(err)
            })

          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消'
            });
          });
        }
        else {
          return false;
        }
      })
    },
    GetAutoDriver() {
      //前后端连接
    },
    goBackPage() {
      this.$router.go(-1)
    },
  },

  mounted() {
    this.initFormDetail();
  },
}
</script>
  
<style scoped>
.container {
  /* height: 100%; */
  width: 95%;
  margin: 0 auto;
  margin-top: 1%;
  background-color: #ffffff;
}

.apply-container {
  width: 90%;
  height: 100%;
  margin: 0 auto;
  /* background-color: #f2f2f2; */
}

.apply-container-head {
  width: 95%;
  height: 30px;
  margin: 0 auto;
}

.apply-container-body {
  width: 95%;
  height: 92%;
  margin: 0 auto;
  background-color: #ffffff;

}

.apply-container-body-title {
  width: 98%;
  height: 5%;
  margin: 0 auto;
  display: flex;
}

.apply-container-body-title-return {
  width: 100%;
  padding-top: 5px;
  display: flex;
  justify-content: flex-end;
}

.apply-container-body-title-line {
  height: 1px;
  width: 98%;
  margin: 5px auto;
}

.apply-container-body-title-font {
  width: 100%;
  height: 99%;
  font-size: 18px;
  font-weight: bold;
  text-align: left;
  padding-top: 10px;
}

.apply-container-body-content {
  width: 85%;
  height: 100%;
  margin: 20px auto;
  display: flex;

}

.apply-container-body-content-submit {
  width: 100%;
  height: 40px;
  display: flex;
  justify-content: flex-end;
  margin-bottom: 20px;
}

.apply-container-footer {
  width: 95%;
  height: 10px;
  margin: 0 auto;
}
</style>